home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group98b.txt
/
000166_icon-group-sender _Mon Aug 31 09:29:09 1998.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
4KB
Return-Path: <icon-group-sender>
Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) with SMTP id JAA00909
for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Mon, 31 Aug 1998 09:29:08 -0700 (MST)
Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
id AA21342; Mon, 31 Aug 1998 09:28:43 -0700
From: gep2@computek.net
Date: Sat, 29 Aug 1998 01:50:56 -0500
Message-Id: <199808290650.BAA28892@axp.cmpu.net>
Mime-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Subject: Re: A hood fan is guard to mind.
To: icon-group@optima.CS.Arizona.EDU
In-Reply-To: <na.ecc435487c.a600a0ardler@argonet.co.uk>
X-Mailer: SPRY Mail Version: 04.00.06.17
Content-Transfer-Encoding: 7bit
Content-Transfer-Encoding: 7bit
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Content-Transfer-Encoding: 7bit
Status: RO
Content-Length: 2742
> can [this program] be shortened by icon clever stuff. The nested
"every"s seem reminiscent of lesser languages:-
Indeed!
> procedure main()
L := ["g","m","h","f"]
every h:=1 to 4 do {
every i:=1 to 4 do {
every j:=1 to 4 do {
every k:=1 to 4 do {
write(fit(h,i,j,k))
}}}}
end
global L,h,i,j,k
procedure fit(a,b,c,d)
if a=b|a=c|a=d|b=c|b=d|c=d then fail
return "A "||L[a]||"ood "||L[b]||"an is "||L[c]||"ard to "||L[d]||"ind."
end
How about something more like:
procedure main()
L := ['g','m','h','f']
every write(fit(!L,!L,!L,!L))
end
global L
procedure fit(a,b,c,d)
if *(a ++ b ++ c ++ d) < 4 then fail
return "A "|| a ||"ood "|| b ||"an is "|| c ||"ard to "|| d ||"ind."
end
Note that L is now a list of character sets rather than character strings! This
should reduce the number of conversions necessary. It also reduces the number
of character set to string conversions required until the final return statement
where everything's concatenated into a final string to return.
The question is whether the character set union (and size) operation takes less
time (or more) than the equals tests used in the original program. (It's
certainly more Icon-like to use the character set union and size). Also, why
convert all the time between subscript numbers and the corresponding characters,
as the original did? Icon iterates just great across strings.
In general, character sets are one of the most sadly neglected features of
Icon... a wonderful feature that deserves to be used more.
You might also want to reduce the list, calling and parameter passing overhead
and move the whole thing into the main procedure, more like:
procedure main()
L = 'gmhf'
every *((a := !L) ++ (b := !L) ++ (c := !L) ++ (d := !L)) = 4 do
write("A "|| a ||"ood "|| b ||"an is "|| c ||"ard to "|| d ||"ind.")
end
You might even want to take advantage of this kind of structure to use four
separate character set constants in the character set concatenation, to
eliminate in advance those words which you know won't be legal words... such as:
procedure main()
every *((a := 'gmhf') ++ (b := 'mf') ++ (c := 'gh') ++ (d := 'mhf')) = 4 do
write("A "|| a ||"ood "|| b ||"an is "|| c ||"ard to "|| d ||"ind.")
end
It's probably possible to use character set differences to extend this principle
and use the difference set for subsequent generations (if you use the same set
for all four iterations), which would eliminate the need for the test for 4
different characters in the resulting set. But that might go beyond elegance
and just get obscure. :-)
Gordon Peterson
http://www.computek.net/public/gep2/
Support the Anti-SPAM Amendment! Join at http://www.cauce.org/